home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 6: Level 6 / 17 Bit - Level 6 (1998)(Epic Marketing)[!].iso / quartz / q1082.dms / q1082.adf / src.lzh / Fig / turn.c < prev    next >
C/C++ Source or Header  |  1991-07-18  |  3KB  |  164 lines

  1. /* 
  2.  *    FIG : Facility for Interactive Generation of figures
  3.  *
  4.  *    Copyright (c) 1985 by Supoj Sutanthavibul (supoj@sally.UTEXAS.EDU)
  5.  *    January 1985.
  6.  *    1st revision : Aug 1985.
  7.  *
  8.  *    %W%    %G%
  9. */
  10. #include "fig.h"
  11. #include "resources.h"
  12. #include "alloc.h"
  13. #include "func.h"
  14. #include "object.h"
  15. #include "paintop.h"
  16.  
  17. #define            TOLERANCE    7
  18.  
  19. extern            (*canvas_kbd_proc)();
  20. extern            (*canvas_locmove_proc)();
  21. extern            (*canvas_leftbut_proc)();
  22. extern            (*canvas_middlebut_proc)();
  23. extern            (*canvas_rightbut_proc)();
  24. extern            null_proc();
  25. extern            set_popupmenu();
  26.  
  27. extern int        pointmarker_shown;
  28.  
  29. extern F_compound    objects;
  30. extern F_line        *line_search();
  31. extern F_spline        *spline_search();
  32.  
  33.             init_turn();
  34.  
  35. turn_selected()
  36. {
  37.     canvas_kbd_proc = null_proc;
  38.     canvas_locmove_proc = null_proc;
  39.     canvas_leftbut_proc = init_turn;
  40.     canvas_middlebut_proc = null_proc;
  41.     canvas_rightbut_proc = set_popupmenu;
  42.     set_cursor(&pick15_cursor);
  43.     }
  44.  
  45. init_turn(x, y)
  46. int    x, y;
  47. {
  48.     F_line        *l;
  49.     F_spline    *s;
  50.     int        dummy;
  51.  
  52.     if ((l = line_search(x, y, TOLERANCE, &dummy, &dummy)) != NULL) {
  53.         if (l->type == T_BOX) return;
  54.         line_2_spline(l);
  55.         turn_selected();
  56.         }
  57.     else if ((s = spline_search(x, y, TOLERANCE, &dummy, &dummy)) != NULL) {
  58.         spline_2_line(s);
  59.         turn_selected();
  60.         }
  61.     }
  62.  
  63. line_2_spline(l)
  64. F_line    *l;
  65. {
  66.     F_spline    *s;
  67.  
  68.     if (num_points(l->points) < 3) {
  69.         put_msg("Can't turn this line into spline");
  70.         return(-1);
  71.         }
  72.     if (pointmarker_shown) toggle_linepointmarker(l);
  73.     draw_line(l, ERASE);
  74.     delete_line(&objects.lines, l);
  75.  
  76.     if (NULL == (Spline_malloc(s))) {
  77.         put_msg(Err_mem);
  78.         return(-1);
  79.         }
  80.  
  81.     if (l->type == T_POLYGON)
  82.         s->type = T_CLOSED_INTERPOLATED;
  83.     else
  84.         s->type = T_OPEN_INTERPOLATED;
  85.     s->style = l->style;
  86.     s->thickness = l->thickness;
  87.     s->color = l->color;
  88.     s->depth = l->depth;
  89.     s->style_val = l->style_val;
  90.     s->pen = l->pen;
  91.     s->area_fill = l->area_fill;
  92.     s->for_arrow = l->for_arrow;
  93.     s->back_arrow = l->back_arrow;
  94.     s->points = l->points;
  95.     s->controls = NULL;
  96.     s->next = NULL;
  97.  
  98.     l->for_arrow = l->back_arrow = NULL;
  99.     l->area_fill = NULL;
  100.     l->pen = NULL;
  101.     l->points = NULL;
  102.  
  103.     if (-1 == create_control_list(s)) {
  104.         free(s);
  105.         return(-1);
  106.         }
  107.  
  108.     remake_control_points(s);
  109.     draw_spline(s, PAINT);
  110.     if (pointmarker_shown) toggle_splinepointmarker(s);
  111.     clean_up();
  112.     set_action_object(F_TURN, O_POLYLINE);
  113.     insert_spline(&objects.splines, s);
  114.     set_latestspline(s);
  115.     set_latestline(l);
  116.     return(1);
  117.     }
  118.  
  119. spline_2_line(s)
  120. F_spline    *s;
  121. {
  122.     F_line    *l;
  123.  
  124.     if (pointmarker_shown) toggle_splinepointmarker(s);
  125.     draw_spline(s, ERASE);
  126.     delete_spline(&objects.splines, s);
  127.  
  128.     /* Now we turn s into a line */
  129.     if (NULL == (Line_malloc(l))) {
  130.         put_msg(Err_mem);
  131.         return(-1);
  132.         }
  133.  
  134.     if (s->type == T_OPEN_INTERPOLATED)
  135.         l->type = T_POLYLINE;
  136.     else if (s->type == T_CLOSED_INTERPOLATED)
  137.         l->type = T_POLYGON;
  138.     l->style = s->style;
  139.     l->thickness = s->thickness;
  140.     l->color = s->color;
  141.     l->depth = s->depth;
  142.     l->style_val = s->style_val;
  143.     l->pen = s->pen;
  144.     l->area_fill = s->area_fill;
  145.     l->for_arrow = s->for_arrow;
  146.     l->back_arrow = s->back_arrow;
  147.     l->points = s->points;
  148.     l->next = NULL;
  149.  
  150.     s->for_arrow = s->back_arrow = NULL;
  151.     s->area_fill = NULL;
  152.     s->pen = NULL;
  153.     s->points = NULL;
  154.  
  155.     draw_line(l, PAINT);
  156.     if (pointmarker_shown) toggle_linepointmarker(l);
  157.     clean_up();
  158.     set_action_object(F_TURN, O_SPLINE);
  159.     insert_line(&objects.lines, l);
  160.     set_latestspline(s);
  161.     set_latestline(l);
  162.     return(1);
  163.     }
  164.